package com.itheima.features.process;

import java.io.IOException;

/**
 * 使用ProcessBuilder去执行windows的exe程序。
 */
public class ProcessBuilderDemo01 {

    public static void main(String[] args) throws IOException {

        // 1. 创建ProcessBuilder对象
        // public ProcessBuilder(String... command): 这个方法的参数用来指定我们所执行的exe程序的命令
        ProcessBuilder processBuilder = new ProcessBuilder() ;

        // 2. 调用方法
        // public ProcessBuilder command(String... command)
        // processBuilder.command("notepad.exe") ;
        processBuilder.command("calc.exe") ;

        // 启动程序： public Process start()
        Process process = processBuilder.start();

        // 获取进程id
        System.out.println("pid ------>>>" + process.pid());

        System.out.println("--------------------------------------------------------");

        /**
         * public ProcessHandle.Info info()
         *
         * Optional<String[]> arguments()  返回进程参数的Strings数组
         * Optional<Instant> startInstant()开始时间
         * Optional<String> user()          返回进程的用户
         * Optional<String> command()       返回进程的可执行路径名
         */
        ProcessHandle.Info info = process.info();
        System.out.println("args ---->>> " + info.arguments() );
        System.out.println("startInstant ---->>> " + info.startInstant() );
        System.out.println("user ---->>> " + info.user() );
        System.out.println("command ---->>> " + info.command() );

    }

}
